<?php
class News extends DB{

	public function getNews(){
		
		$sql = "SELECT * FROM news order by date desc";
		return parent::fetchAll($sql);
	}
	
	public function addNews($title,$content){
		$sql = "INSERT INTO `news` VALUES (:id,:title,:content,:date)";
		$field = array(':id' => '',
					   ':title' => $title,
					   ':content' => $content,
					   ':date' => date("Y-m-d h:i:s")
					  );	
		return parent::updateDB($sql,$field);			
	}
	
	public function getNewsById($id){
		$sql = "SELECT * from news where id='$id'";
		return parent::fetchRow($sql);
		
	}
	
	public function editNews($id,$title,$content){
		$DB = new DB();
		$sql = "UPDATE `news` set title=?,content=? where id='$id'";
		$field = array($title,$content);
		return parent::updateDB($sql,$field);	
	}
	
	public function delNews($id){
		global $db;
		$sql = "delete from `news` where id='$id'";
		return $db->query($sql);		
	}
	


}
?>